const unitTool = {
    methods:{
        isArray(input) {
            return input instanceof Array || Object.prototype.toString.call(input) === '[object Array]';
        },
        //字符串长度
        charLength(list){
            if(!this.isArray(list)) return 0
            let len = 0
            for(const item of list){
                for(const i of item.riskList){
                    for(const j of i.mainDuty){
                        for(const k in j){
                            if(j[k]){
                                len += j[k].length
                            }
                        }
                    }
                }
            }
            return len
        },
        charLength1(list){
            if(!this.isArray(list)) return 0
            let len = 0
            for(const i of list){
                for(const j of i.mainDuty){
                    for(const k in j){
                        if(j[k]){
                            len += j[k].length
                        }
                    }
                }
            }
            return len
        },
        //处理保额单位
        companyChange(num){
            if(Number(num) > 10000){
                return (Number(num)%10000?(Number(num)/10000).toFixed(2):(Number(num)/10000)) +'万元'
            } else {
                return Number(num) +'元'
            }
        },
        //处理缺口单位
        companyChange1(num,flag){
            if(Number(num) == 0){
                return '无'
            }else{
                return (flag?'交':'')+(Number(num)%10000?(Number(num)/10000).toFixed(2):(Number(num)/10000)) + (flag?'万元/年':'万')
            }
        },
        //处理年金单位
        companyChange2(min,max){
            if(Number(max) == 0 || !max || max ==='null'){
                return '无'
            }else{
                if(Number(max) > Number(min)){
                    return '领'+(Number(min)%10000?(Number(min)/10000).toFixed(2):Number(min)/10000)+'—'+ (Number(max)%10000?(Number(max)/10000).toFixed(2):Number(max)/10000) + '万元/年'
                }else{
                    return '领'+ (Number(max)%10000?(Number(max)/10000).toFixed(2):Number(max)/10000) +'万元/年'
                }
            }
        },
    }
}

export default unitTool